const app = getApp();
const db = wx.cloud.database();
const _ = db.command;
const gameid='54ad1eea6230accc1662c4fb436fb2cc'

Page({
  /**
   * 页面的初始数据
   */
  data: {
    total: 0,
    isPhone: true,
    flag: false,
    isJoin: false,
    isTime: true,
    interval: 3000,
    duration: 1500,
    activeColor: '#fff',
    admin: false,
    images: [
      'cloud://cloud1-6gso5km2a228414f.636c-cloud1-6gso5km2a228414f-1310085182/index/1.jpg',
      'cloud://cloud1-6gso5km2a228414f.636c-cloud1-6gso5km2a228414f-1310085182/index/2.jpg',
      'cloud://cloud1-6gso5km2a228414f.636c-cloud1-6gso5km2a228414f-1310085182/index/3.jpg',
      'cloud://cloud1-6gso5km2a228414f.636c-cloud1-6gso5km2a228414f-1310085182/index/4.jpg',
      'cloud://cloud1-6gso5km2a228414f.636c-cloud1-6gso5km2a228414f-1310085182/index/5.jpg'
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let _openid=app.globalData.openid
    db.collection('user').where({
      _openid
    }).get().then(res=>{
      this.setData({
        user:res.data[0]
      });
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.gethd()
    this.getTotal();

  },

  getTotal() {
    db.collection('user').where({
      joinner:true
    }).count().then(res => {
      this.setData({
        total: res.total
      })
    })
  },


  gethd(){
    db.collection('gamejf').doc(gameid).get().then(res=>{
      let hd=res.data
      hd.time=hd.time.getTime()
      hd.entime=hd.entime.getTime()
      this.setData({
        hd
      })
    })
  },
  nameFocus: function() {
    this.setData({
      flag: true
    });
  },
  nameBlur: function(e) {
    if (e.detail.value) {
      this.setData({
        name: e.detail.value
      });
    } else {
      this.setData({
        flag: false
      });
    }
  },

  toLogin(){
    wx.navigateTo({
      url: '../login/login?ac=1',
    })
  },

  toResult() {
    wx.switchTab({
      url: '../my/my',
    })
  },
  tozw(){
    wx.navigateTo({
      url: '../zhangWang/zhangWang',
    })
  },

  torule(e){
    wx.navigateTo({
      url: '../rule/rule',
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.gethd()
    this.getTotal();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    return {
      title: '《敲可爱战棋》',
      path: '/pages/login/login',
      }
  }

})